﻿/*********************************************************************
*                                                                    *
*                SEGGER Microcontroller GmbH & Co. KG                *
*        Solutions for real time microcontroller applications        *
*                                                                    *
**********************************************************************
*                                                                    *
* C-file generated by:                                               *
*                                                                    *
*        GUI_Builder for emWin version 5.26                          *
*        Compiled Aug 18 2014, 17:12:05                              *
*        (c) 2014 Segger Microcontroller GmbH & Co. KG               *
*                                                                    *
**********************************************************************
*                                                                    *
*        Internet: www.segger.com  Support: support@segger.com       *
*                                                                    *
**********************************************************************
*/

// USER START (Optionally insert additional includes)
// USER END


/*********************************************************************
*
*       Defines
*
**********************************************************************
*/
// USER START (Optionally insert additional defines)
#include "includes.h"
#include  "app.h"
// USER END

/*********************************************************************
*
*       Static data
*
**********************************************************************
*/

// USER START (Optionally insert additional static data)
// USER END

/*********************************************************************
*
*       _aDialogCreate
*/
static const GUI_WIDGET_CREATE_INFO _aDialogCreateBreathing[] = {
  { FRAMEWIN_CreateIndirect, "Breathing", 0, 0, 0, 240, 320, 0, 0x0, 0 },
  { SLIDER_CreateIndirect, "rSlider", GUI_ID_SLIDER0, 35, 85, 30, 120, 8, 0x0, 0 },
  { SLIDER_CreateIndirect, "gSlider", GUI_ID_SLIDER1, 100, 85, 30, 120, 8, 0x0, 0 },
  { SLIDER_CreateIndirect, "bSlider", GUI_ID_SLIDER2, 165, 85, 30, 120, 8, 0x0, 0 },
  { EDIT_CreateIndirect, "rEdit", GUI_ID_EDIT0, 30, 50, 40, 30, 0, 0x3, 0 },
  { EDIT_CreateIndirect, "gEdit", GUI_ID_EDIT1, 95, 50, 40, 30, 0, 0x3, 0 },
  { EDIT_CreateIndirect, "bEdit", GUI_ID_EDIT2, 160, 50, 40, 30, 0, 0x3, 0 },
  // USER START (Optionally insert additional widgets)
  // USER END
};

/*********************************************************************
*
*       Static code
*
**********************************************************************
*/
// USER START (Optionally insert additional static code)
static uint8_t  rValue,gValue,bValue;
// USER END

/*********************************************************************
*
*       _cbDialog
*/
static void _cbDialogBreathing(WM_MESSAGE * pMsg) {
  WM_HWIN hItem;
  int     NCode;
  int     Id;
  // USER START (Optionally insert additional variables)
  // USER END

  switch (pMsg->MsgId) {
	case WM_DELETE:
		// USER START (Optionally insert additional code for further widget initialization)
		OS_INFO("Breathingapp delete\n");
		TIM3_Breathing_Close();		
		Flag_ICON101 = 0;
		UserApp_Flag = 0;
		WM_DeleteWindow(KEYBOARD);
		/* LED ¶Ë¿Ú³õÊ¼»¯ */
		LED_GPIO_Config(); 
		tpad_flag=0;
		// USER END
	break;
  case WM_INIT_DIALOG:
    //
    // Initialization of 'Breathing'
    //
		hItem = pMsg->hWin;
		FRAMEWIN_SetTitleHeight(hItem, 20);
		FRAMEWIN_SetTextColor(hItem,GUI_DARKGRAY);
		FRAMEWIN_SetFont(hItem, GUI_FONT_16B_ASCII);
		FRAMEWIN_AddCloseButton(hItem,FRAMEWIN_BUTTON_RIGHT,0);
    //
    // Initialization of 'rEdit'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, GUI_ID_EDIT0);
    EDIT_SetFont(hItem, GUI_FONT_20B_ASCII);
    EDIT_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
		EDIT_SetUlongMode(hItem,rValue,0,255);		
    //
    // Initialization of 'gEdit'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, GUI_ID_EDIT1);
    EDIT_SetUlongMode(hItem,gValue,0,255);
    EDIT_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
    EDIT_SetFont(hItem, GUI_FONT_20B_ASCII);
    //
    // Initialization of 'bEdit'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, GUI_ID_EDIT2);
    EDIT_SetUlongMode(hItem,bValue,0,255);
    EDIT_SetFont(hItem, GUI_FONT_20B_ASCII);
    EDIT_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
		//
		// Initialization of 'rSlider'
		//
		hItem = WM_GetDialogItem(pMsg->hWin, GUI_ID_SLIDER0);
		SLIDER_SetRange(hItem,0,255);
		SLIDER_SetValue(hItem,rValue);
		//
		// Initialization of 'gSlider'
		//
		hItem = WM_GetDialogItem(pMsg->hWin, GUI_ID_SLIDER1);
		SLIDER_SetRange(hItem,0,255);
		SLIDER_SetValue(hItem,gValue);
		//
		// Initialization of 'bSlider'
		//
		hItem = WM_GetDialogItem(pMsg->hWin, GUI_ID_SLIDER2);
		SLIDER_SetRange(hItem,0,255);
		SLIDER_SetValue(hItem,bValue);
    // USER START (Optionally insert additional code for further widget initialization)
    // USER END
    break;
  case WM_NOTIFY_PARENT:
    Id    = WM_GetId(pMsg->hWinSrc);
    NCode = pMsg->Data.v;
    switch(Id) {
    case GUI_ID_SLIDER0: // Notifications sent by 'rSlider'
      switch(NCode) {
      case WM_NOTIFICATION_CLICKED:
        // USER START (Optionally insert code for reacting on notification message)
        // USER END
        break;
      case WM_NOTIFICATION_RELEASED:
        // USER START (Optionally insert code for reacting on notification message)
        // USER END
        break;
      case WM_NOTIFICATION_VALUE_CHANGED:
        // USER START (Optionally insert code for reacting on notification message)
				rValue=SLIDER_GetValue(WM_GetDialogItem(pMsg->hWin, GUI_ID_SLIDER0));
				EDIT_SetValue(WM_GetDialogItem(pMsg->hWin, GUI_ID_EDIT0),rValue);
				SetColorValue(rValue,gValue,bValue);
				WM_InvalidateWindow(pMsg->hWin);
        // USER END
        break;
      // USER START (Optionally insert additional code for further notification handling)
      // USER END
      }
      break;
    case GUI_ID_SLIDER1: // Notifications sent by 'gSlider'
      switch(NCode) {
      case WM_NOTIFICATION_CLICKED:
        // USER START (Optionally insert code for reacting on notification message)
        // USER END
        break;
      case WM_NOTIFICATION_RELEASED:
        // USER START (Optionally insert code for reacting on notification message)
        // USER END
        break;
      case WM_NOTIFICATION_VALUE_CHANGED:
        // USER START (Optionally insert code for reacting on notification message)
				gValue=SLIDER_GetValue(WM_GetDialogItem(pMsg->hWin, GUI_ID_SLIDER1));
				EDIT_SetValue(WM_GetDialogItem(pMsg->hWin, GUI_ID_EDIT1),gValue);
				SetColorValue(rValue,gValue,bValue);
				WM_InvalidateWindow(pMsg->hWin);
        // USER END
        break;
      // USER START (Optionally insert additional code for further notification handling)
      // USER END
      }
      break;
    case GUI_ID_SLIDER2: // Notifications sent by 'bSlider'
      switch(NCode) {
      case WM_NOTIFICATION_CLICKED:
        // USER START (Optionally insert code for reacting on notification message)
        // USER END
        break;
      case WM_NOTIFICATION_RELEASED:
        // USER START (Optionally insert code for reacting on notification message)
        // USER END
        break;
      case WM_NOTIFICATION_VALUE_CHANGED:
        // USER START (Optionally insert code for reacting on notification message)
				bValue=SLIDER_GetValue(WM_GetDialogItem(pMsg->hWin, GUI_ID_SLIDER2));
				EDIT_SetValue(WM_GetDialogItem(pMsg->hWin, GUI_ID_EDIT2),bValue);
				SetColorValue(rValue,gValue,bValue);
				WM_InvalidateWindow(pMsg->hWin);
        // USER END
        break;
      // USER START (Optionally insert additional code for further notification handling)
      // USER END
      }
      break;
    case GUI_ID_EDIT0: // Notifications sent by 'rEdit'
      switch(NCode) {
      case WM_NOTIFICATION_CLICKED:
        // USER START (Optionally insert code for reacting on notification message)
        // USER END
        break;
      case WM_NOTIFICATION_RELEASED:
        // USER START (Optionally insert code for reacting on notification message)
				if(!keypadflag) keypadapp(WM_GetDialogItem(pMsg->hWin, GUI_ID_EDIT0),1);
        // USER END
        break;
      case WM_NOTIFICATION_VALUE_CHANGED:
        // USER START (Optionally insert code for reacting on notification message)
				rValue=EDIT_GetValue(WM_GetDialogItem(pMsg->hWin, GUI_ID_EDIT0));
				SLIDER_SetValue(WM_GetDialogItem(pMsg->hWin, GUI_ID_SLIDER0),rValue);
				SetColorValue(rValue,gValue,bValue);
        // USER END
        break;
      // USER START (Optionally insert additional code for further notification handling)
      // USER END
      }
      break;
    case GUI_ID_EDIT1: // Notifications sent by 'gEdit'
      switch(NCode) {
      case WM_NOTIFICATION_CLICKED:
        // USER START (Optionally insert code for reacting on notification message)
        // USER END
        break;
      case WM_NOTIFICATION_RELEASED:
        // USER START (Optionally insert code for reacting on notification message)
				if(!keypadflag) keypadapp(WM_GetDialogItem(pMsg->hWin, GUI_ID_EDIT1),1);
        // USER END
        break;
      case WM_NOTIFICATION_VALUE_CHANGED:
        // USER START (Optionally insert code for reacting on notification message)
				gValue=EDIT_GetValue(WM_GetDialogItem(pMsg->hWin, GUI_ID_EDIT1));
				SLIDER_SetValue(WM_GetDialogItem(pMsg->hWin, GUI_ID_SLIDER1),gValue);
				SetColorValue(rValue,gValue,bValue);
        // USER END
        break;
      // USER START (Optionally insert additional code for further notification handling)
      // USER END
      }
      break;
    case GUI_ID_EDIT2: // Notifications sent by 'bEdit'
      switch(NCode) {
      case WM_NOTIFICATION_CLICKED:
        // USER START (Optionally insert code for reacting on notification message)
        // USER END
        break;
      case WM_NOTIFICATION_RELEASED:
        // USER START (Optionally insert code for reacting on notification message)
				if(!keypadflag) keypadapp(WM_GetDialogItem(pMsg->hWin, GUI_ID_EDIT2),1);
        // USER END
        break;
      case WM_NOTIFICATION_VALUE_CHANGED:
        // USER START (Optionally insert code for reacting on notification message)
				bValue=EDIT_GetValue(WM_GetDialogItem(pMsg->hWin, GUI_ID_EDIT2));
				SLIDER_SetValue(WM_GetDialogItem(pMsg->hWin, GUI_ID_SLIDER2),bValue);
				SetColorValue(rValue,gValue,bValue);
        // USER END
        break;
      // USER START (Optionally insert additional code for further notification handling)
      // USER END
      }
      break;
    // USER START (Optionally insert additional code for further Ids)
    // USER END
    }
    break;
  // USER START (Optionally insert additional message handling)
	case WM_PAINT:	
		GUI_SetBkColor(GUI_WHITE);
		GUI_Clear();
		//
		// Draw RGB values
		//
		GUI_SetColor((U32)rValue);
		GUI_FillRect(30, 5, 70, 45);
		GUI_SetColor(((U32)gValue) << 8);
		GUI_FillRect(95, 5, 135, 45);
		GUI_SetColor(((U32)bValue) << 16);
		GUI_FillRect(160, 5, 200, 45);
		//
		// Draw resulting color
		//
		GUI_SetColor(rValue | (((U32)gValue) << 8) | (((U32)bValue) << 16));
		GUI_FillCircle(230/2,250,40);
		break;
  // USER END
  default:
    WM_DefaultProc(pMsg);
    break;
  }
}

/*********************************************************************
*
*       Public code
*
**********************************************************************
*/
/*********************************************************************
*
*       CreateBreathing
*/
void FUN_ICON101Clicked(void)
{
	WM_HWIN hWin;
	rValue=218;
	gValue=37;
	bValue=196;
	OS_INFO("Breathingapp create\n");
	
	TIM3_Breathing_Init();
	SetColorValue(rValue,gValue,bValue);
  hWin=GUI_CreateDialogBox(_aDialogCreateBreathing, GUI_COUNTOF(_aDialogCreateBreathing), _cbDialogBreathing, WM_HBKWIN, 0, 0);
	while(Flag_ICON101)
	{				
		if(tpad_flag)WM_DeleteWindow(hWin);		
		GUI_Delay(10); 				
	}
	
}

// USER START (Optionally insert additional public code)
// USER END

/*************************** End of file ****************************/
